import { DataTypes, Model } from "sequelize";
import sequelize from "@db/sequelize";
import { MetroStation } from "./MetroStation";

export class City extends Model {
    declare id: number;
    declare name: string;
    declare MetroStations?: MetroStation[];
}

City.init(
    {
        id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true,
            unique: true,
        },
        name: {
            type: DataTypes.STRING,
            allowNull: false,
        },
    },
    {
        tableName: "geo-cities",
        sequelize,
        timestamps: false,
    }
);

City.hasMany(MetroStation, {
    foreignKey: "cityId",
});
